package com.wz.project.scj.ktp.controller;

import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.Result;
import com.wz.project.scj.ktp.service.KTPinService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author kalista
 * @Description
 * @Date 2021/11/3  9:50
 **/
@Controller
@RequestMapping("/rf/ktp")
@Api(value = "空托盘操作")
public class KTPcontroller extends BaseController {

    private String prefix = "scj/ktp";

    @Autowired
    private KTPinService ktPinService;


    @GetMapping("/in")
    public String ktpIN() {
        return prefix + "/KTP_in";
    }

    @GetMapping("/out")
    public String ktpOUT() {
        return prefix + "/KPT_out";
    }

    /**
     * 空托盘入库
     * @param trayCode
     * @return
     */
    @PostMapping("/KTP_in")
    @ResponseBody
    @ApiOperation(value = "空托盘入库",notes = "扫描托盘码进行不同类型托盘入库")
    public Result ktpRK(String trayCode) {
        Result result = new Result();
        if(trayCode.length() ==8){
            if ( ktPinService.KTPinJob(trayCode)){
                result.setMsg("操作成功！");
            }else {
                result.setMsg("托盘条码重复，请重新选择条码！");
            }
        }else{
            result.setMsg("托盘条码长度错误！");
        }


        return result ;
    }

    /**
     * 空托盘出库

     * @return
     */
    @PostMapping("/KTP_out")
    @ResponseBody
    public Result ktpCK(String quantity,String type,String exit) {

        Result result = new Result();
        if ( ktPinService.KTPoutJob(quantity, type,exit)){
            result.setMsg("操作成功！");
        }else {
            result.setMsg("无空托盘库存！");
        }
        return result ;
    }
}
